package com.ehouse.database;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;

import com.ehouse.provider.MainContentProvider;


public class IrrigationTable {
	// Database table
		public static final String NAME = "irrigation";
		public static final String COLUMN_ID = "_id";
		public static final String COLUMN_STATE = "state";

		public static final Uri CONTENT_URI = Uri.parse(MainContentProvider.BASE_URI.toString() + NAME);
		
		// Database creation SQL statement
		public static final String DATABASE_CREATE = "create table " 
				+ NAME
				+ "(" + COLUMN_ID + " integer primary key autoincrement, " 
				+ COLUMN_STATE + " integer not null " + ");";

		public static void update(ContentResolver cr, int[] irrigationItems){

		    for(int i =0; i < irrigationItems.length; i++){
		    	String[] projection = new String[]{IrrigationTable.COLUMN_ID, IrrigationTable.COLUMN_STATE};
			  Cursor query = cr.query(IrrigationTable.CONTENT_URI, projection, null, null, null);

	  	      ContentValues values = new ContentValues();

	   	      values.put(IrrigationTable.COLUMN_STATE, irrigationItems[i]);   
	   
		   	   if(query.getCount() ==0)
		   	      cr.insert(IrrigationTable.CONTENT_URI, values);
		   	   else{
		   		   cr.update(IrrigationTable.CONTENT_URI, values, null, null);
		   	   }
		   	   
		   	query.close();
		    }
		    
		}
}
